 #include <vector>       
#include "Net.h"
#include <sys/epoll.h>  
#include <sys/socket.h>
#include <pthread.h>    
#include <semaphore.h>  //信号量
#include <atomic>       
#include <map>          
#include <arpa/inet.h>
#include "public.h"
#include "MemoryPoolObj.h"

void sClient::Init()
{
    iCurrsequence = 0;
}
void sClient::GetOneToUse()
{
    
    ++iCurrsequence;

    fd = -1; 

    curStat     = _PKG_HD_INIT;      

    precvbuf    = dataHeadInfo;        

    irecvlen        = g_TcpHeaderSize;    

    pRecvMemPointer = nullptr;                                     //既然没new内存，那自然指向的内存地址先给nullptr

    iThrowsendCount = 0;                                              //原子的

    psendMemPointer = nullptr;                                     //发送数据头指针记录

    events = 0;                                                                 //epoll事件先给0 
    
    //nSendCount = 0; 

    b_In = false;

    m_bClosed = false;

    nSendCount =0;		

    nRecvCount =0;
}

//回收回来一个连接的时候做一些事
void sClient::PutOneToFree()
{
    ++iCurrsequence;

    if (pRecvMemPointer != nullptr)//我们曾经给这个连接分配过接收数据的内存，则要释放内存
    {
        MemPoolObj::GetMemoryPool()->Free((void*)pRecvMemPointer);
        pRecvMemPointer = nullptr;
    }

    if (psendMemPointer != nullptr) //如果发送数据的缓冲区里有内容，则要释放内存
    {
        MemPoolObj::GetMemoryPool()->Free((void*)psendMemPointer);
        psendMemPointer = nullptr;
    }

    iThrowsendCount = 0;                              //设置不设置感觉都行

    nSendCount = 0;

    nRecvCount = 0;

	m_bClosed   = true;

    b_In              = true;
}
